const obj = {
  a: {
    b: {
      c: {
        d: 22,
      }
    }
  }
}
const key = 'a.b.c.d';
function getValue(obj, path) {
  if (!obj) {
    return;
  }
  let tempObj = obj;
  const pathArr = path.split('.');
  for (let i = 0; i < pathArr.length; i++) {
    tempObj = tempObj[pathArr[i]];
    if (i === pathArr.length - 1) {
      return tempObj;
    } else if (typeof tempObj !== 'object') {
      break;
    }
  }
  return null;
}
console.log(getValue(obj, key));